# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Yejun Yang yejunx AT gmail DOT com

pkgname=ziproxy
pkgver=3.3.2
pkgrel=4
pkgdesc="forwarding, non-caching, compressing HTTP proxy server"
arch=('loong64' 'x86_64')
url="http://ziproxy.sourceforge.net/"
license=('GPL2')
depends=('giflib' 'libpng' 'libjpeg' 'zlib' 'jasper' 'libsasl')
backup=(etc/ziproxy/ziproxy.conf
	etc/ziproxy/bo_exception.list
	etc/ziproxy/http.passwd
	etc/ziproxy/noprocess.list
	etc/ziproxy/replace.list
	etc/xinetd.d/ziproxy
	var/lib/ziproxy/error/400.html
	var/lib/ziproxy/error/404.html
	var/lib/ziproxy/error/407.html
	var/lib/ziproxy/error/408.html
	var/lib/ziproxy/error/409.html
	var/lib/ziproxy/error/500.html
	var/lib/ziproxy/error/503.html)
source=(https://downloads.sourceforge.net/project/ziproxy/ziproxy/ziproxy-$pkgver/ziproxy-$pkgver.tar.bz2
	ziproxy.logrotate
	ziproxy.sysusers
	ziproxy.tmpfiles
	ziproxy.xinetd
	build-fix.patch)
sha256sums=('76a1fc62c76dfa1a8d0784193aba20a96e214dd615b7927b497ceee5059699f1'
            '6087c75dc9a9d493365bb599bf4dcb72fab95da54ea9b75418616cf0cd9be5e3'
            'a2aa82f37b0436e99cda917d994a728d0e8b08ffc9c3f87dd3b6e509a0b36a14'
            '28e6c059c8bf0c9291c20157a356991de67b2459dc3b333f58bd93e02bbb3e01'
            '27c2ce6207c24e1af5bc1cb7b350ef5ca12ea3bdaf7b5f10f00251ec1292c3a0'
            'dd462a5604aba5bfea8e12a4abe6db317f8d45bc7614696e6d7379cf8120a616')

prepare() {
  cd "$srcdir"/$pkgname-$pkgver
#  sed -i '1,1i#include <string.h>' src/qparser.c
#  patch -p1 <"$srcdir"/build-fix.patch
}

build() {
  cd "$srcdir"/$pkgname-$pkgver
  [ -f Makefile ] || CFLAGS+=' -fcommon' ./configure --prefix=/usr --with-jasper
  make
}

package() {
  cd "$srcdir"/$pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  install -d "$pkgdir"/var/lib/ziproxy/error
  install -d "$pkgdir"/etc/conf.d

  sed -i 's#var/ziproxy#var/lib/ziproxy#' etc/ziproxy/ziproxy.conf
  cp -a etc/ziproxy "$pkgdir"/etc/ziproxy
  install -m644 var/ziproxy/error/* "$pkgdir"/var/lib/ziproxy/error
  echo "ZIPROXY_ARGS=\"-c /etc/ziproxy/ziproxy.conf\"" >"$pkgdir"/etc/conf.d/ziproxy
  install -Dm0644 "$srcdir"/ziproxy.logrotate "$pkgdir"/etc/logrotate.d/ziproxy
  install -Dm0644 "$srcdir"/ziproxy.xinetd "$pkgdir"/etc/xinetd.d/ziproxy
  install -Dm0644 "$srcdir"/ziproxy.sysusers "$pkgdir"/usr/lib/sysusers.d/ziproxy.conf
  install -Dm0644 "$srcdir"/ziproxy.tmpfiles "$pkgdir"/usr/lib/tmpfiles.d/ziproxy.conf
}
